package screen;
/**
 * @author HIENDEPTRAI
 */
import java.util.ArrayList;
import java.util.List;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.ParticleEmitterBox2D;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.ContactImpulse;
import com.badlogic.gdx.physics.box2d.ContactListener;
import com.badlogic.gdx.physics.box2d.EdgeShape;
import com.badlogic.gdx.physics.box2d.Filter;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.Manifold;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.Pool;
import common.Constant;
import common.ShapeRenderer;

import entity.Entity;

public class Stage {
	
	public int[] shipDestroy = new int[7];
	public TextureRegion[] shipsRegion = new TextureRegion[7];

	private final int INIT_SHIP = 10;
	private final int MAX_SHIP = 20;
	private final int INIT_MISSILE = 15;
	private final int MAX_MISSILE = 20;
	private final int INIT_FIGHTER = 20;
	private final int MAX_FIGHTER = 30;
	private final int NUM_SUPPORT_PLANE = 4;
	private int numShip;	
	private int totalShip;
	
	public int totalWave;
	public int currentWave = 1;
	public int waveTime;
	public boolean waveTimeUp = false;
	public int countShipWave;
	public boolean missionCompleted = false;
	public boolean winGame = false;
	public int[] typeShip;
	public boolean onceInit = false;
	private int rangeAppearTo;
	private int rangeAppear;
	private int amountAppear;
	public boolean useUnionFlag = false;
	public boolean forcesAttack = false;
	public boolean reborn = false;
	private int rebornTime;
	private int[] lanes = new int[]{200, 130, 60};
	public int oilStrength = 106;
	public int flagBlood = 106;
	
	public Array<Entity> entities = new Array<Entity>();
//	private List<Entity> levelEntity = new ArrayList<Entity>();
//	private int TIME = 300;
//	private int countOfShip = 0;
	
	public static World world;
	public int level = 10;
	
	private Texture background;
	private TextureRegion bgRegion;
	
	private int stateTime;
	private float statePlaneSPTime;
	public int shipAppear;
	public int shipDestroyCount;
	private int planeSPTimeAppear;
	public boolean attack = false;
	public boolean changeWeapon = false;
	
	private TextureRegion islandRegion;
	public ShapeRenderer renderer;
	public int countScore;
	
	public Stage() {
	}
	
	public void Initialize(int level) {
		
	}
	
	public void render(SpriteBatch spriteBatch) {
		world.step(Gdx.app.getGraphics().getDeltaTime(), 3, 3);
		
		
	}
	
	private void createWorld(){
		world = new World(new Vector2(0.0f, -10.0f), true);
		BodyDef groundBodyDef = new BodyDef();
		groundBodyDef.type = BodyDef.BodyType.StaticBody;
		
		Body groundBody = world.createBody(groundBodyDef);
		EdgeShape mapBounds = new EdgeShape();


		mapBounds.set(new Vector2(0.0f, 480 / Constant.PIXELS_PER_METER),
				new Vector2(800 / Constant.PIXELS_PER_METER, 480
						/ Constant.PIXELS_PER_METER));
		groundBody.createFixture(mapBounds, 0);

//		mapBounds.set(new Vector2(0.0f, 0 / Constant.PIXELS_PER_METER),
//				new Vector2(800 / Constant.PIXELS_PER_METER, 0
//						/ Constant.PIXELS_PER_METER));
		
//		groundBody.createFixture(mapBounds, 0);
		ArrayList<Fixture> fixtures = groundBody.getFixtureList();
		Filter filter = new Filter();
		filter.categoryBits = Constant.CATEGORY_SCENERY;
		filter.maskBits = Constant.MASK_CATEGORY_SCENERY;
		for (int i = 0;i < fixtures.size();i++) fixtures.get(i).setFilterData(filter);
		mapBounds.dispose();
		world.setContactListener(new ContactListener() {

			@Override
			public void preSolve(Contact contact, Manifold arg1) {
				
			}
			
			@Override
			public void postSolve(Contact contact, ContactImpulse arg1) {
				
			}
			
			@Override
			public void endContact(Contact contact) {
				
			}
			
			@Override
			public void beginContact(Contact contact) {
			}
		});
	}	
	
	public void tick() {
	}
	
	public void add (Entity e) {
		entities.add(e);
	}
	public World getWorld() {
		return world;
	}

}
